"""
-*- coding: utf-8 -*-
@Time    : 2021/4/5 10:09
@Author  : Hu
@Email   : 624611978@qq.com
@File    : 作业.py
"""
from decimal import Decimal

#三乐购物系统
def PrintGoods(goods:dict):  #定义商品打印函数
    print("以下为商品列表".center(48, '#'))
    for i,j in goods.items():
        print(f"商品编号：{i}  品名：{j['name']}  价格：{j['price']}元")

def PrintBuys(buys:dict):  #定义已购买打印函数
    print("以下为已购买列表".center(47,'#'))
    for i,j in buys.items():
        print(f"{i}*{j}")

print("欢迎来到三乐购物系统".center(46,'#'))
User = {'Admin':'Admin'}
Goods = {'g01':{'name':'苹果','price':Decimal(1.5)},'g02':{'name':'西瓜','price':4},'g03':{'name':'打火机','price':1}}  #定义商品表
Uinput = input("请输入账号：")
Pinput = input("请输入密码：")
for i,j in User.items():
    if Uinput == i and Pinput == j:  #判断账户密码
        print("登陆成功！".center(50,'#'))
        Umoney = Decimal(input("请输入预算："))
        BuyDict = {'苹果':0,'西瓜':0,'打火机':0}  #定义已购买表
        while True:
            print('#'*54)
            print("1：查看商品信息 2：查看已购买信息 3：购买商品 exit：退出系统")
            Option = input("请在上述功能中选择：")
            if Option == '1':
                PrintGoods(Goods)
            elif Option == '2':
                PrintBuys(BuyDict)
            elif Option == '3':
                print('#' * 54)
                BuyName = input("请输入要购买的商品编号：")
                BuyNum = int(input("请输入数量："))
                if Umoney >= Goods[BuyName]['price'] * BuyNum:  #判断余额是否足够
                    Umoney -= (Goods[BuyName]['price'] * BuyNum)  #减去相应余额
                    print(f"购买成功，本次消费{Goods[BuyName]['price'] * BuyNum}，余额为：{Umoney}")
                    BuyDict[Goods[BuyName]['name']] += BuyNum  #增加已购买列表中商品对应数量
                else:
                    print("您的余额不足")
            elif Option == 'exit':
                PrintBuys(BuyDict)
                print(f"您的余额为{Umoney}元")
                print("成功退出".center(50,'#'))
                break
        break
else:
    print("登陆失败，系统退出".center(47,'#'))